import { http } from "@/utils/http";

// 部门接口类型定义
export interface DeptQueryParams {
  name?: string;
  page?: number;
  per_page?: number;
}

export interface DeptCreateParams {
  name: string;
}

export interface DeptUpdateParams {
  department_id: number;
  name: string;
}

export interface DeptDeleteParams {
  department_id: number;
}

export interface DeptInfo {
  id: number;
  name: string;
}

export interface DeptQueryResult {
  code: number;
  message: string;
  data: DeptInfo[];
  pagination?: {
    page: number;
    per_page: number;
    total: number;
    pages: number;
  };
}

export interface DeptOperationResult {
  code: number;
  message: string;
  data?: DeptInfo | [];
}

/** 查询部门 - 支持模糊查询和分页查询 */
export const queryDept = (params?: DeptQueryParams) => {
  return http.request<DeptQueryResult>("post", "/api/department/query", {
    data: params
  });
};

/** 创建部门 */
export const createDept = (data: DeptCreateParams) => {
  return http.request<DeptOperationResult>("post", "/api/department/add", {
    data
  });
};

/** 更新部门 */
export const updateDept = (data: DeptUpdateParams) => {
  return http.request<DeptOperationResult>("post", "/api/department/update", {
    data
  });
};

/** 删除部门 */
export const deleteDept = (data: DeptDeleteParams) => {
  return http.request<DeptOperationResult>("post", "/api/department/delete", {
    data
  });
};
